<script setup lang="ts">
import upgradeHelperTable from '@/components/Echart/Table/upgradeHelperTable.vue'
import { storeToRefs } from 'pinia'
import { reactive, onBeforeMount } from 'vue'
import { useDealerDataStore } from '@/stores/module/dealerData'
import { useRoute } from 'vue-router'
import { headersStore } from '@/stores/apiHeader'
import api from '@/api/index'
const dealerDataStore = useDealerDataStore() // 创建store实例
const { dealerDisupgradeinfo } = storeToRefs(dealerDataStore)
const headerStore = headersStore()
const route = useRoute()
const disid = route.query.uid // 经销商id
headerStore.setDistributorKey(disid.toString()) // 设置经销商id
let planid = ''
let pvalue = ''
dealerDisupgradeinfo?.value?.info?.plan?.forEach((item: any) => {
  planid = item.pkey
  pvalue = item.pvalue
})
const target_level = Number(
  dealerDisupgradeinfo?.value?.info?.upgradeinfo?.target_level_value
)
let tableData = []
const getdealerDisupgradeinfo = () => {
  tableData = []
  if (
    dealerDisupgradeinfo &&
    dealerDisupgradeinfo.value &&
    dealerDisupgradeinfo.value.info &&
    dealerDisupgradeinfo.value.info.isplan
  ) {
    const params = {
      planid,
      disid,
      target_level,
    }

    api.dealerGetplaninfo({ params }).then((res: any) => {
      if (res.code == 0 && res.data) {
        tableData.push(...res.data.info?.planinfo)
      }
    })
  }
}

const print = reactive([
  {
    pvalue: pvalue,
  },
])
onBeforeMount(() => {
  getdealerDisupgradeinfo()
})
</script>
<template>
  <card-box>
    <template v-slot:title>
      <h1>{{ dealerDisupgradeinfo.title }}</h1>
    </template>

    <upgradeHelperTable :table-data="tableData" :print="print" />
  </card-box>
</template>
